module Piston
  module PluginManager
    class ShowPluginManager
      include System::Windows::Input::ICommand
      def add_CanExecuteChanged(h)
        @change_handlers << h
      end

      def remove_CanExecuteChanged(h)
        @change_handlers.remove(h)
      end

      def can_execute(arg)
        @can_execute
      end

      def execute(arg)
        xaml_file = File.expand_path(File.dirname(__FILE__) + "/../view/dialog.xaml")
        plugin_manager = System::Windows::Markup::XamlReader.load_file xaml_file
        plugin_data_list = Piston::PluginManager::PluginDataList.new
        plugin_manager.data_context = plugin_data_list
        plugin_manager.show_dialog

        @change_handlers.each { |h| h.Invoke(self, System::EventArgs.new) }
      end
        
      def initialize
        @change_handlers = []
        @can_execute = true
      end
    end
  end
end